package stu.day9_day18;

import java.util.HashMap;
import java.util.Scanner;

public class train2 {
    public static void main(String[] args) {

        HashMap<String,Integer> map = new HashMap<>();
        String[] pai = new String[]{"3","4","5","6","7","8","9","10","J","Q","K","A","2","B","C","2","1"};
        for(String c:pai){
            map.put(c,4);
        }

        Scanner sc =new Scanner(System.in);
        String[] str1 = sc.nextLine().split("-");
        String[] str2 = sc.nextLine().split("-");
        for (String s:str1){
            int num = map.get(s)-1;
            map.put(s,num);
        }
        for (String s:str2){
            int num = map.get(s)-1;
            map.put(s,num);
        }

        int[] array = new int[12];

        for(int i=0;i<12;i++){
            if(i==0){
                int num = map.get(pai[i])>0?1:0;
                array[i] = num;
            }else {
                int num = map.get(pai[i])>0?array[i-1]+1:0;
                array[i] = num;
            }
        }

        for(int i=0;i<12;i++){
            System.out.print(array[i]+" ");
        }


        int max=5;
        int index=0;
        for(int ix=0;ix<array.length;ix++){
            if(array[ix]>=max){
                max=array[ix];
                index = ix;
            }

        }
        System.out.println(max+" "+index);


        if(index>0){
            StringBuilder sb = new StringBuilder();
            int j = (index-max+1);
            sb.append(pai[j]);
            for(int k=0;k<max-1;k++){
                j = j+1;
                sb.append("-");
                sb.append(pai[j]);
            }
            System.out.println(sb.toString());


        }else {
            System.out.println("NO-CHAIN");
        }








    }

}
